<%@ page language="java" contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<head>
    <jsp:include page="../common/common.jsp"/>
</head>
<body class="page-header-fixed">
<jsp:include page="../common/header.jsp"/>
<div class="clearfix">
</div>
<div class="page-container">
<div class="page-sidebar-wrapper"><jsp:include page="../common/menu.jsp"/></div>
<div class="page-content-wrapper">
    <div class="page-content">
        <div class="row">
            <div class="col-md-12">
                <form class="form-horizontal form-row-seperated" action="${path}/doc/save">
                    <div class="portlet box purple">
                        <div class="portlet-title">
                            <div class="caption">
                                <i class="fa fa-shopping-cart"></i>详细信息
                            </div>
                            <div class="actions btn-set">
                                <button type="button" class="btn blue" onclick="save()">
                                    <i class="fa fa-check"></i> 保存
                                </button>
                                <button type="button" class="btn green" onclick="examine('1')">
                                    <i class="fa fa-long-arrow-up"></i> 审核通过
                                </button>
                                <button type="button" class="btn red" onclick="examine('2')">
                                    <i class="fa fa-exclamation"></i> 审核不通过
                                </button>
                            </div>
                        </div>
                        <div class="portlet-body">
                            <div class="tabbable">
                                <div class="tab-content no-space">
                                    <div class="tab-pane active" id="tab_general">
                                        <div class="form-body">
                                            <div class="form-group">
                                                <label class="col-md-2 control-label">栏目:
                                                    <span class="required">*</span>
                                                </label>

                                                <div class="col-md-5">
                                                    <select name="columnId" class="form-control">
                                                        <c:forEach items="${bizClass}" var="s">
                                                            <option value="${s.id}"
                                                                    <c:if test="${entity.columnId==s.id}">selected="selected"</c:if> >${s.value0}</option>
                                                        </c:forEach>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-2 control-label">标题:
                                                    <span class="required">*</span>
                                                </label>

                                                <div class="col-md-5">
                                                    <input type="text" id="title" name="title"
                                                           class="form-control measure-input" datatype="*1-80"
                                                           value="${entity.title}"/>
                                                </div>
                                                <div class="col-md-5">
                                                    &nbsp;可输入<b><span id="title_len">80</span></b> 个字符
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-2 control-label">关键词:</label>

                                                <div class="col-md-5">
                                                    <input id="keyword" name="keyword" type="text"
                                                           class="form-control tags medium"
                                                           value="${entity.keyword}"/>
                                                </div>
                                            </div>
                                            <input type="hidden" name="author" value="${entity.author}"/>
                                            <input type="hidden" id="imgUrl" name="imgUrl" value="${entity.imgUrl}"/>
                                            <input type="hidden" id="fileUrl" name="fileUrl" value="${entity.fileUrl}"/>

                                            <div class="form-group">
                                                <label class="col-md-2 control-label">封面：</label>

                                                <div class="col-md-8">
                                                    <div class="fileinput fileinput-new" data-provides="fileinput">
                                                        <div class="fileinput-new thumbnail"
                                                             style="width: 300px; height: 150px;">
                                                            <img src="${entity.imgUrl}">
                                                        </div>
                                                        <div class="fileinput-preview fileinput-exists thumbnail"
                                                             style="max-width: 300px; max-height: 150px;">
                                                        </div>
                                                        <div>
                                                            <span class="btn default btn-file">
                                                                <span class="fileinput-new">
                                                                     选择图片
                                                                </span>
                                                                <span class="fileinput-exists">
                                                                     修改图片
                                                                </span>
                                                                <input type="file" id="file" name="file"/>
                                                            </span>
                                                            <a href="#" class="btn default fileinput-exists"
                                                               data-dismiss="fileinput">
                                                                移除图片
                                                            </a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-2 control-label">摘要:
                                                    <span class="required">*</span>
                                                </label>

                                                <div class="col-md-8">
                                                    <textarea cols="80" class="form-control" datatype="*"
                                                              name="summary">${entity.summary}</textarea>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-md-2 control-label">内容:
                                                    <span class="required">*</span>
                                                </label>

                                                <div class="col-md-10">
                                                    <%-- <jsp:include page="common/editor.jsp" /> --%>
                                                    <input id="context" type="hidden" name="context">
                                                    <script id="editor" type="text/plain"
                                                            style="height:500px;">${entity.context}</script>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-md-2 control-label">售价:
                                                </label>

                                                <div class="col-md-8">
                                                    <input type="text" id="price" name="price"
                                                           class="form-control measure-input" readonly="readonly"
                                                           value="${entity.score}"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-2 control-label">文档附件：</label>

                                                <div class="col-md-8">
                                                    <div class="fileinput fileinput-new" data-provides="fileinput">
                                                        <div class="fileinput-new thumbnail"
                                                             style="width: 300px; height: 25px;">
                                                            <c:if test="${entity.fileUrl!='' && entity.fileUrl!= null }">
                                                                <a href="${path}/doc/down/${entity.id}" target="_blank">下载附件</a>
                                                            </c:if>
                                                        </div>
                                                        <div class="fileinput-preview fileinput-exists thumbnail"
                                                             style="max-width: 300px; max-height: 25px;">
                                                        </div>
                                                        <div>
                                                            <span class="btn default btn-file">
                                                                <span class="fileinput-new">
                                                                     选择上传文档
                                                                </span>
                                                                <span class="fileinput-exists">
                                                                     修改文件
                                                                </span>
                                                                <input type="file" id="file2" name="file2"/>
                                                            </span>
                                                            <a href="#" class="btn default fileinput-exists"
                                                               data-dismiss="fileinput">
                                                                移除文件
                                                            </a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-2 control-label">审核状态:</label>
                                                <div class="col-md-8">
                                                    <c:if test="${ entity.status == '0'}">待审核</c:if>
                                                    <c:if test="${ entity.status == '1'}">审核通过</c:if>
                                                    <c:if test="${ entity.status == '2'}">审核不通过</c:if>
                                                    <c:if test="${ entity.status == '3'}">禁用</c:if>
                                                    <input type="hidden" id="status" name="status"
                                                           value="${entity.status}"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-2 control-label">审核意见:
                                                    <span class="required">*</span>
                                                </label>

                                                <div class="col-md-8">
                                                    <textarea cols="80" class="form-control" id="postil"
                                                              name="postil">${entity.postil}</textarea>
                                                </div>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="portlet-title">
                            <div class="actions btn-set">
                                <button type="button" class="btn blue" onclick="save()">
                                    <i class="fa fa-check"></i> 保存
                                </button>
                                <button type="button" class="btn green" onclick="examine('1')">
                                    <i class="fa fa-long-arrow-up"></i> 审核通过
                                </button>
                                <button type="button" class="btn red" onclick="examine('2')">
                                    <i class="fa fa-exclamation"></i> 审核不通过
                                </button>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" id="id" name="id" value="${entity.id}">
                </form>
            </div>
        </div>
    </div>
</div>
</div>
<jsp:include page="../common/footer.jsp"/>
<script type="text/javascript" src="${path}/assets/plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/jquery-inputmask/jquery.inputmask.bundle.min.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/jquery.pwstrength.bootstrap/src/pwstrength.js"></script>
<script type="text/javascript" src="${path}/assets/scripts/biz/ajaxfileupload.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    var form;
    $(function () {
        UE.getEditor('editor');
        form = $("form").Validform({
            tiptype: function (msg, o, cssctl) {
                //msg：提示信息;
                //o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
                //cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
                if (!o.obj.is("form")) {//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
                    var objtip = o.obj.siblings(".Validform_checktip");
                    cssctl(objtip, o.type);
                    objtip.text(msg);
                } else {
                    var objtip = o.obj.find("#msgdemo");
                    cssctl(objtip, o.type);
                    objtip.text(msg);
                }
            },
            postonce: true,
            showAllError: true,
            callback: function (data) {
                if (data && data.statusCode === 200) {
                    window.location.href = _path + "/doc/list";
                } else {
                    alert("保存失败！");
                }
            }
        });
        if($("#status").val() == '1') {
            $("button[id='btnExamineOk']").hide();
            $("button[id='btnExamineNo']").hide();
            $("#postil").attr("readonly", "readonly");
        }
    });
    //保存前检验
    function save() {
        var context = UE.getEditor('editor').getContent();
        if (!/[\w\W]+/.test(context)) {
            alert("内容不能为空");
            return;
        }
        $("#context").val(context);
        ajaxFileUpload();
    }
    //Ajax保存
    function ajaxFileUpload() {
        if ($("#file2").val() !== "") {
            $.ajaxFileUpload({
                url: '${path}/conf/upload',
                secureuri: false,
                fileElementId: 'file2',
                dataType: 'json',
                success: function (data, status) {
                    if (data.statusCode === 200) {
                        alert(data.uri);
                        $("#fileUrl").val(data.uri);
                    } else {
                        alert(data.info);
                        return false;
                    }
                }
            });
        }
        if ($("#file").val() !== "") {
            $.ajaxFileUpload({
                url: '${path}/conf/upload',
                secureuri: false,
                fileElementId: 'file',
                dataType: 'json',
                success: function (data, status) {
                    if (data.statusCode === 200) {
                        $("#imgUrl").val(data.uri);
                        form.ajaxPost(false, true, _path + "/doc/save");
                    } else
                        alert(data.info);
                }
            });
        } else {
            form.ajaxPost(false, true, _path + "/doc/save");
        }
        return false;
    }
    //审核
    function examine(stuats) {
        if ($("#status").val() == '1') {
            alert("该记录已经审核通过,不能在做其他操作！");
            return false;
        }
        if (stuats == '2' && $("#postil").val() == '') {
            alert("审核意见不能为空！");
            return false;
        }
        App.ajax(_path + "/doc/update", "status=" + stuats + "&id=" + $("#id").val() + "&postil=" + $("#postil").val(), function (data) {
            switch (data.statusCode) {
                case 200 :
                    alert("操作成功！");
                    break;
                case 500 :
                    alert(data.info);
                    break;
                default :
                    alert("操作失败！");
                    break;
            }
            window.location.reload();
        });
    }
</script>
</body>
</html>